<template>
  <div class="box">HelloA 组件

    <button v-copy.trim.number.lazy="'1234'">点我复制</button>
  </div>
</template>

<script>
import Clipboard from 'clipboard'

export default {

  directives: {
    copy: function(el, binding) {
      // console.log(binding)

      const clipboard = new Clipboard(el, {
        // 复制的文本
        text() { return binding.value },
        // 动作，剪切还是复制
        action() { return 'copy' }
      })

      // 绑定两个事件
      clipboard.on('success', () => {
        alert('复制成功')
      })
      clipboard.on('error', () => {
        alert('复制失败')
      })
    }
  }

};
</script>

<style scoped lang="scss">
.box {
  color: green;
  background-color: green;
}
</style>
